package com.tool.emulator.apple2;

import com.tool.emulator.mos6502.CPU6502;

/**
 * FlipFlop.java @author tl 2011-6-26
 */
public class FlipFlop {
	final CPU6502 cpu;
	private volatile long startCycles = -1;

	FlipFlop(CPU6502 cpu) {
		this.cpu = cpu;
	}

	boolean get(long current_cycles) {
		return this.startCycles >= 0 && current_cycles - startCycles < cpu.getFreq();
	}

	void set(long current_cycles) {
		if (get(current_cycles))
			this.startCycles = -1;
		else
			this.startCycles = current_cycles;
	}

	void reset() {
		this.startCycles = -1;
	}
}
